/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fat.euro.beans;

import fat.euro.entities.Client;
import fat.euro.jpa.ClientJpaController;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import javax.transaction.UserTransaction;

/**
 *
 * @author VAIO
 */
@ManagedBean
@RequestScoped
public class ClientManagedBean {
    private List<Client> list;
    private ClientJpaController jpa;
    /**
     * Creates a new instance of ClientManagedBean
     */
    public ClientManagedBean() {   
        try {
            InitialContext ctx=new InitialContext();
            UserTransaction utx = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
            jpa=new ClientJpaController(utx,Persistence.createEntityManagerFactory("FatPushServerPU"));
        } catch (NamingException ex) {
            Logger.getLogger(ClientManagedBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public List<Client> getList() {
        if(list==null) {
            list=new ArrayList();
            list=jpa.findClientEntities();
        }
        return list;
    }

    public void setList(List<Client> list) {
        this.list = list;
    }
    
    
}
